﻿using FarseerGames.FarseerPhysics;
using System;
using System.Diagnostics;

namespace Organized
{
    public class Physics : Component
    {
        //the physics simulator
        public PhysicsSimulator PhysicsSimulator;

        //wether or not we should update
        public bool UpdatePhysics {
            get{ return PhysicsSimulator.Enabled;}
            set{ PhysicsSimulator.Enabled = value;}
        }

        public Physics()
        {
            //Create simulator
            PhysicsSimulator = new PhysicsSimulator();

            //SETUP
            //for stacked objects, simultaneous collision are the bottlenecks so limit them to 2 per geometric pair.
            PhysicsSimulator.MaxContactsToDetect = 2;
            //Setup the simulator
            UpdatePhysics = true;
            //scaling allows better sinchronisation during heavy framerate drops
            PhysicsSimulator.Scaling.Enabled = false;
            
        }

        public override void Update()
        {
            if (UpdatePhysics)
            {
                PhysicsSimulator.Update(1f);
            }
            base.Update();
        }

    }
}